﻿namespace AE.Remoting {
    public class Settings {
        private static Settings _Current;
        public static Settings Current {
            get {
                if (_Current == null) _Current = new Settings();
                return _Current;
            }
            set { _Current = value; }
        }

        /// <summary>
        /// True if RemotingHost is not empty, and not Remoting.ServiceThread.IsRemoted 
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public bool RemotingEnabled {
            get { return (!string.IsNullOrEmpty(RemotingHost) || !string.IsNullOrEmpty(RemotingUrl)) & !Utilities.IsRemoted; }
        }

        private int _RemotingPort = 90;
        /// <summary>
        /// This is a required client and server setting--defaulting to 90.
        /// </summary>
        public int RemotingPort {
            get { return _RemotingPort; }
            set { _RemotingPort = value; }
        }

        /// <summary>
        /// The host name of the application server
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public string RemotingHost { get; set; }

        /// <summary>
        /// Url used for IIS hosted remoting.
        /// </summary>
        /// <value></value>
        /// <returns></returns>
        /// <remarks></remarks>
        public string RemotingUrl { get; set; }

        private int _RemotingTimeout = 90;
        /// <summary>
        /// Timeout in seconds
        /// </summary>
        public int RemotingTimeout {
            get { return _RemotingTimeout; }
            set { _RemotingTimeout = value; }
        }

        public enum RemotingModes {
            None,
            TcpIp,
            Web
        }

        private RemotingModes? _RemotingMode;
        public RemotingModes RemotingMode {
            get {
                if (!_RemotingMode.HasValue) {
                    if (!string.IsNullOrEmpty(RemotingHost)) {
                        _RemotingMode = RemotingModes.TcpIp;
                    } else if (!string.IsNullOrEmpty(RemotingUrl)) {
                        _RemotingMode = RemotingModes.Web;
                    } else {
                        _RemotingMode = RemotingModes.None;
                    }
                }
                return _RemotingMode.Value;
            }
        }
    }
}
 